import { UserConfig } from "vite";
import { createVitePlugins } from "./build/vite";
import { pathResolve } from "./build/utils";
import { root, env } from "./build/env";

export default (): UserConfig => {
    return {
        root,
        base: "/",
        server: {
            open: env.VITE_OPEN === "true",
            proxy: {
                "/app/geoserver": {
                    target: "http://localhost:8080",
                    changeOrigin: true,
                    rewrite: (path) => path.replace(/^\/app\/geoserver/, "/geoserver")
                },
                "/app": {
                    target: "http://localhost:8070",
                    changeOrigin: true,
                    rewrite: (path) => path.replace(/^\/app/, "/app")
                }
            }
        },
        build: {
            rollupOptions: {
                input: {
                    main: "./index.html",
                    fileWorker: "src/modules/file/worker/worker.ts"
                },
                output: {
                    entryFileNames: "[name].bundle.js"
                }
            }
        },
        resolve: {
            extensions: [".mjs", ".js", ".ts", ".jsx", ".tsx", ".json", ".scss", ".css"],
            alias: [
                {
                    find: /@\//,
                    replacement: `${pathResolve("src")}/`
                }
            ]
        },
        plugins: createVitePlugins()
    };
};
